package com.gem.service.impl;

import com.gem.domain.User;
import com.gem.mapper.UserMapper;
import com.gem.service.UserService;
import com.gem.util.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: 玲
 * @Description:
 * @create 2019-10-25 15:44
 * @Modified By:
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper mapper;

    @Override
    public User findById(Integer uid) {
        return mapper.findById(uid);
    }

    @Override
    public User findByName(String personname) {
        return mapper.findByName(personname);
    }

    @Override
    public User findByNameWitdM(String personname) {
        return mapper.findByNameWithM(personname);
    }

    @Override
    public Integer save(User user) {
        return mapper.save(user);
    }

    @Override
    public Integer deleteById(Integer uid) {
        return mapper.deleteById(uid);
    }

    @Override
    public Integer updatePassword(String password, Integer uid) {
        return mapper.updatePassword(password, uid);
    }

    @Override
    public List<User> findMmembers() {
        return mapper.findMmembers();
    }

    @Override
    public List<User> findMmembersWithNull() {
        return mapper.findMmembersWithNull();
    }

    @Override
    public List<User> findMmembersByPersonName(String dsSeller) {
        return mapper.findMmembersByPersonName(dsSeller);
    }

    @Override
    public List<User> findMmembersBySalesName(String crSales) {
        return mapper.findMmembersBySalesName(crSales);
    }

    @Override
    public List<User> findEmembers() {
        return mapper.findEmembers();
    }

    @Override
    public List<User> findJmembers() {
        return mapper.findJmembers();
    }

    @Override
    public List<User> findHrc() {
        return mapper.findHrc();
    }

    @Override
    public User login(User user) {
        try {
            user.setPassword(Md5Util.encodeByMd5(user.getPassword()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mapper.login(user);
    }

    @Override
    public User findByUsername(User user) {
        return mapper.findByUsername(user);
    }

    @Override
    public List<User> findAllUser() {
        try {
            return mapper.findAllUser();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<User> selectAllByPersonName(String personName) {
        return mapper.findUserByName(personName);
    }
}
